package com.iptv.grape.ui.adpt;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.iptv.grape.R;
import com.iptv.grape.beans.ApkBean;

import java.util.List;

public class AppMgrAdpt  extends BaseAdapter {
    private Context ctx;
    private List<ApkBean> datas;
    public AppMgrAdpt(Context ctx, List<ApkBean> datas){
        this.ctx = ctx;
        this.datas = datas;
    }
    @Override
    public int getCount() {
        return datas==null?0:datas.size();
    }

    @Override
    public Object getItem(int position) {
        position = datas.size()>position?position:datas.size()-1;
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        position = datas.size()>position?position:datas.size()-1;
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder holder;
        if(null== convertView){
            holder = new Holder();
            convertView  = View.inflate(ctx, R.layout.item_app_mgr,null);
            holder.ivIcon = convertView.findViewById(R.id.ivApkIcon);
            holder.tvName = convertView.findViewById(R.id.tvApkName);
            convertView.setTag(holder);
        }else{
            holder = (Holder) convertView.getTag();
        }
        position = datas.size()>position?position:datas.size()-1;
        ApkBean  info = datas.get(position);
        holder.ivIcon.setImageDrawable( info.icon);
        holder.tvName.setText(info.name);
        return convertView;
    }


    private class Holder{
        private ImageView ivIcon;
        private TextView tvName;


    }
}
